package face.pay.web.agency.enterprise.user;

import face.pay.system.annotation.CurrentUser;
import face.pay.constant.RoleCode;
import face.pay.constant.UserType;
import face.pay.dao.UserInfoDao;
import face.pay.entity.UserInfo;
import face.pay.util.ResultMessage;
import face.pay.util.page.PageData;
import face.pay.util.page.PageParam;
import face.pay.web.com.user.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value="/enterprise_user")
@Slf4j
public class EnterpriseUserController {

    @Autowired
    private IUserService iUserService;


    @Autowired
    private UserInfoDao userInfoDao;

    /**
     * 企业 商家用户
     * @return
     */
    @RequestMapping(value = "/list")
    public String manager(){
        return  "agency/enterprise/user/userList";
    }

    @RequestMapping(value = "/user_detail")
    public String detail( String userId, Model model){

        UserInfo mch = this.userInfoDao.getById(new Integer(userId));
        model.addAttribute("mch",mch);
        return "agency/enterprise/user/userDetail";
    }


    @RequestMapping(value = "/queryData")
    @ResponseBody
    public PageData data(@CurrentUser UserInfo logUser, PageParam pageParam, UserInfo userInfo) {

        userInfo.setType(UserType.ENTERPRISE);
        userInfo.setDeleted(0);
        return  this.iUserService.queryPage(logUser,userInfo,pageParam);

    }


    @RequestMapping("/edit")
    @ResponseBody
    public ResultMessage editUser(@CurrentUser UserInfo logUser,UserInfo userInfo) {

        /**
         * 设置默认的类型
         */
        userInfo.setType(UserType.ENTERPRISE);
        userInfo.setDeleted(0);
        return  iUserService.editUser( logUser,RoleCode.ROLE_ENTERPRISE_MANAGER,userInfo);

    }
}
